﻿using Collections.Pooled;
using furion.blog.Domain.Shared.Attribute;
using furion.blog.Domain.Shared.Vo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace furion.blog.Domain.Shared.Enum
{
    public enum ShopStatusEnum
    {
        /// <summary>
        /// 临时保存(未提交审批)
        /// </summary>
        [EnumAttribute(Name = "未提交审核", Desc = "未提交审核", Value = "Saving")]
        Saving,
        /// <summary>
        /// 待审核
        /// </summary>
        [EnumAttribute(Name = "待审核", Desc = "待审核", Value = "Checking")]
        Checking,
        /// <summary>
        /// 审核通过
        /// </summary>
        [EnumAttribute(Name = "审核通过", Desc = "审核通过", Value = "Passed")]
        Passed,
        /// <summary>
        /// 下架(停止营业，不会在app显示该门店信息)
        /// </summary>
        [EnumAttribute(Name = "封号", Desc = "封号", Value = "Ban")]
        Ban,
        /// <summary>
        /// 审核不通过
        /// </summary>
        [EnumAttribute(Name = "审核不通过", Desc = "审核不通过", Value = "UnPass")]
        UnPass,
        /// <summary>
        /// 门店自行关店休息(必须Passed之后才能操作)
        /// </summary>
        [EnumAttribute(Name = "下线", Desc = "下线", Value = "Off")]
        Off,
        /// <summary>
        /// 门店自行上线营业(必须Passed之后才能操作)
        /// </summary>
        [EnumAttribute(Name = "上线", Desc = "上线", Value = "On")]
        On,
    }


    public class ShopStatus
    {
        /// <summary>
        /// 返回键值集合
        /// </summary>
        /// <returns></returns>
        public static async Task<PooledSet<NameValueVO>> Items()
        {
            return await Task.Run(() =>
            {
                PooledSet<NameValueVO> ret = new PooledSet<NameValueVO>();
                Type t = typeof(ShopStatusEnum);
                FieldInfo fd = null;
                foreach (var name in t.GetEnumNames())
                {
                    fd = t.GetField(name);
                    var attr = fd.GetCustomAttribute(typeof(EnumAttribute), false) as EnumAttribute;
                    ret.Add(new NameValueVO { Name = attr.Name, Value = attr.Value });
                }
                return ret;
            });
        }

        /// <summary>
        /// 是否拥有该值
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public static async Task<bool> ContainsKey(string key) {
            return await Task.Run(() =>
            {
                PooledSet<NameValueVO> ret = new PooledSet<NameValueVO>();
                Type t = typeof(ShopStatusEnum);
                FieldInfo fd = null;
                foreach (var name in t.GetEnumNames())
                {
                    fd = t.GetField(name);
                    var attr = fd.GetCustomAttribute(typeof(EnumAttribute), false) as EnumAttribute;
                    if (attr.Value.ToString() == key) {
                        return true;
                    }
                }
                return false;
            });
        }
    
    }

}
